package com.jiyi.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiyi.bean.maintenance.DetectItemParent;
import com.jiyi.bean.maintenance.DetectSystemJson.Equipment;
import com.jiyi.event.CheckUploadEvent;
import com.jiyi.view.PickPopView;
import com.jiyi.widget.MultiLineRadioGroup;
import com.jiyi.widget.MultiLineRadioGroup.OnCheckedChangedListener;
import com.jiyi.widget.picselect.PicSelectConstans;
import com.jiyi.widget.picshow.ImagePagerActivity;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.utils.DateUtils;
import com.swift.utils.DeviceUtil;
import com.swift.utils.GlideUtil;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Date;

/**
 * @author zlw
 */
public class DetectItemAdapter extends BaseExpandableListAdapter {
	private Context mContext;
	ArrayList<DetectItemParent> mList = new ArrayList<DetectItemParent>();
	LayoutInflater inflater;
	// boolean isDelModel;
	private int max = 4;
	private InputMethodManager imm;
	PickPopView mPickPopView;
	private final int TYPE_0 = 0;
	private final int TYPE_1 = 1;
	private final int TYPE_2 = 2;
	private final int TYPE_3 = 3;
	private final int TYPE_4 = 4;
	private final int TYPE_5 = 5;
	private int catePosition;

	public DetectItemAdapter(Context context, int position,
			ArrayList<DetectItemParent> liveList, PickPopView mPickPopView) {
		this.mContext = context;
		this.catePosition = position;
		this.mList = liveList;
		this.mPickPopView = mPickPopView;
		imm = DeviceUtil.getInstance().getImm();
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getGroupCount() {
		return mList.size();
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		int childSize = mList.get(groupPosition).getChildList().size();
		return childSize;
	}

	@Override
	public Object getGroup(int i) {
		return getGroup(i);
	}

	@Override
	public Object getChild(int i, int i1) {
		return getChild(i, i1);
	}

	@Override
	public long getGroupId(int i) {
		return i;
	}

	@Override
	public long getChildId(int i, int i1) {
		return i1;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public View getGroupView(final int position, boolean isExpanded,
			View convertView, ViewGroup viewGroup) {
		GroupHolder groupHolder;
		if (convertView == null) {
			convertView = View.inflate(mContext,
					R.layout.item_detect_item_head, null);
			groupHolder = new GroupHolder(convertView);
			convertView.setTag(groupHolder);
		} else {
			groupHolder = (GroupHolder) convertView.getTag();
		}
		groupHolder.mGroupTitleTv.setText(mList.get(position).getTitle());

		boolean isFinish = false;
		for (int i = 0; i < mList.get(position).getChildList().size(); i++) {
			Equipment detectItem = mList.get(position).getChildList().get(i);
			if (detectItem.getWithout() == 1 || detectItem.getCannot_test() == 1
					|| detectItem.getImageList().size() > 0) {
				isFinish = true;
				break;
			}
		}
		if (isFinish) {
			groupHolder.tvMore.setText("此项已操作");
		} else {
			groupHolder.tvMore.setText("");
		}

		boolean isError = false;
		for (int i = 0; i < mList.get(position).getChildList().size(); i++) {
			Equipment detectItem = mList.get(position).getChildList().get(i);
			if (!TextUtils.isEmpty(detectItem.getFault())
					&& detectItem.getFault().equals("1")) {
				isError = true;
				break;
			}
		}

		Drawable defaultDraw = mContext.getResources().getDrawable(
				R.drawable.detectitem_head_tip);
		defaultDraw.setBounds(0, 0, defaultDraw.getMinimumWidth(),
				defaultDraw.getMinimumHeight());
		if (isError) {
			// 根据有异常的项，来对头部进行标志处理
			Drawable errorDraw = mContext.getResources().getDrawable(
					R.mipmap.icon_error_tip);
			errorDraw.setBounds(0, 0, errorDraw.getMinimumWidth(),
					errorDraw.getMinimumHeight());
			groupHolder.mGroupTitleTv.setCompoundDrawables(defaultDraw, null,
					errorDraw, null);
		} else {
			groupHolder.mGroupTitleTv.setCompoundDrawables(defaultDraw, null,
					null, null);
		}

		if (isExpanded) {
			Drawable searchDraw = mContext.getResources().getDrawable(
					R.mipmap.icon_extend);
			searchDraw.setBounds(0, 0, searchDraw.getMinimumWidth(),
					searchDraw.getMinimumHeight());
			groupHolder.tvMore.setCompoundDrawables(null, null, searchDraw,
					null);
		} else {
			Drawable searchDraw = mContext.getResources().getDrawable(
					R.mipmap.icon_extend);
			searchDraw.setBounds(0, 0, searchDraw.getMinimumWidth(),
					searchDraw.getMinimumHeight());
			groupHolder.tvMore.setCompoundDrawables(null, null, searchDraw,
					null);
		}

		return convertView;
	}

	@Override
	public View getChildView(final int groupPosition, final int childPosition,
			boolean b, View convertView, ViewGroup viewGroup) {
		DetectItemParent detectItemParent = mList.get(groupPosition);
		Equipment detectItem = detectItemParent.getChildList().get(
				childPosition);
		detectItem.setParentPosition(groupPosition);
		detectItem.setChildPosition(childPosition);
		int type = getChildType(groupPosition, childPosition);
		switch (type) {
		case TYPE_0:

			// 有当前状态的选择按钮
			final ChildHolderZore childHolderZore;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_detect_self_test,
						viewGroup, false);
				childHolderZore = new ChildHolderZore(convertView);
				convertView.setTag(childHolderZore);
			} else {
				childHolderZore = (ChildHolderZore) convertView.getTag();
			}

			childHolderZore.etRecordValue.setTag(detectItem);
			childHolderZore.etMalfValue.setTag(detectItem);
			childHolderZore.gvPic.setTag(R.id.tag_equip, detectItem);

			childHolderZore.etRecordValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderZore.etRecordValue
									.getTag();
							bean.setRecord(s.toString());
						}
					});
			childHolderZore.etMalfValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderZore.etMalfValue
									.getTag();
							bean.setContent(s.toString());
						}
					});

			childHolderZore.tvDetectTitle.setText(detectItemParent.getTitle());
			childHolderZore.tvCode.setText(detectItem.getTagid());
			childHolderZore.tvPosition.setText(detectItem.getPlace());
			childHolderZore.tvDetectMethod.setText(detectItem.getReference());
			childHolderZore.etRecordValue.setText(TextUtils.isEmpty(detectItem
					.getRecord()) ? detectItem.getDefault_record() : detectItem
					.getRecord());
			childHolderZore.etMalfValue.setText(detectItem.getContent());
			childHolderZore.rgFault
					.setOnCheckChangedListener(new OnCheckedChangedListener() {

						@Override
						public void onItemChecked(MultiLineRadioGroup group,
								int position, boolean checked) {
							if (position == 0) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 1) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("1");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 2) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
								// childHolderZore.llPics.setVisibility(View.GONE);
							} else {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
							}

							EventBus.getDefault().post(
									new CheckUploadEvent(catePosition));
							notifyDataSetChanged();

						}
					});

			if (detectItem.getWithout() == 1) {
				// 无此项
				childHolderZore.rgFault.setItemChecked(2);
			} else if (detectItem.getCannot_test() == 1) {
				// 无法测试
				childHolderZore.rgFault.setItemChecked(3);
			} else {
				// 有此项
				if (TextUtils.isEmpty(detectItem.getFault())
						|| detectItem.getFault().equals("0")) {
					childHolderZore.rgFault.setItemChecked(0);
				} else {
					childHolderZore.rgFault.setItemChecked(1);
				}
			}
			if (detectItem.getWithout() == 1
					|| detectItem.getCannot_test() == 1) {
				childHolderZore.llDetail.setVisibility(View.GONE);
			} else {
				childHolderZore.llDetail.setVisibility(View.VISIBLE);
			}

			childHolderZore.etRecordValue.setText(TextUtils.isEmpty(detectItem
					.getRecord()) ? detectItem.getDefault_record() : detectItem
					.getRecord());

			refreshAdapter((MyAdapter) childHolderZore.gvPic.getTag(),
					childHolderZore.gvPic,
					(Equipment) childHolderZore.gvPic.getTag(R.id.tag_equip));

			break;
		case TYPE_1:
			// 有上次值、当前值
			final ChildHolderOne childHolderOne;
			if (convertView == null) {
				convertView = inflater.inflate(
						R.layout.item_detect_system_pre_cur, viewGroup, false);
				childHolderOne = new ChildHolderOne(convertView);
				convertView.setTag(childHolderOne);
			} else {
				childHolderOne = (ChildHolderOne) convertView.getTag();
			}

			childHolderOne.etRecordValue.setTag(detectItem);
			childHolderOne.etMalfValue.setTag(detectItem);
			childHolderOne.etPre.setTag(detectItem);
			childHolderOne.etCur.setTag(detectItem);
			childHolderOne.gvPic.setTag(R.id.tag_equip, detectItem);

			childHolderOne.tvDetectTitle.setText(detectItemParent.getTitle());
			childHolderOne.tvCode.setText(detectItem.getTagid());
			childHolderOne.tvPosition.setText(detectItem.getPlace());
			childHolderOne.tvDetectMethod.setText(detectItem.getReference());
			childHolderOne.etRecordValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							// 获得Edittext所在position里面的Bean，并设置数据
							Equipment bean = (Equipment) childHolderOne.etRecordValue
									.getTag();
							bean.setRecord(s.toString());
						}
					});
			childHolderOne.etMalfValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							// 获得Edittext所在position里面的Bean，并设置数据
							Equipment bean = (Equipment) childHolderOne.etMalfValue
									.getTag();
							bean.setContent(s.toString());
						}
					});

			childHolderOne.etPre.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					// 获得Edittext所在position里面的Bean，并设置数据
					Equipment bean = (Equipment) childHolderOne.etPre.getTag();
					bean.setValue_1(s.toString());
				}
			});

			childHolderOne.etCur.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					// 获得Edittext所在position里面的Bean，并设置数据
					Equipment bean = (Equipment) childHolderOne.etCur.getTag();
					bean.setValue(s.toString());
				}
			});

			childHolderOne.etRecordValue.setText(TextUtils.isEmpty(detectItem
					.getRecord()) ? detectItem.getDefault_record() : detectItem
					.getRecord());
			childHolderOne.etMalfValue.setText(detectItem.getContent());
			childHolderOne.etPre.setText(detectItem.getValue_1());
			childHolderOne.etCur.setText(detectItem.getValue());

			refreshAdapter((MyAdapter) childHolderOne.gvPic.getTag(),
					childHolderOne.gvPic,
					(Equipment) childHolderOne.gvPic.getTag(R.id.tag_equip));

			childHolderOne.rgFault
					.setOnCheckChangedListener(new OnCheckedChangedListener() {

						@Override
						public void onItemChecked(MultiLineRadioGroup group,
								int position, boolean checked) {
							if (position == 0) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 1) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("1");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 2) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
								// childHolderZore.llPics.setVisibility(View.GONE);
							} else {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
							}

							EventBus.getDefault().post(
									new CheckUploadEvent(catePosition));
							notifyDataSetChanged();

						}
					});

			if (detectItem.getWithout() == 1) {
				// 无此项
				childHolderOne.rgFault.setItemChecked(2);
			} else if (detectItem.getCannot_test() == 1) {
				// 无法测试
				childHolderOne.rgFault.setItemChecked(3);
			} else {
				// 有此项
				if (TextUtils.isEmpty(detectItem.getFault())
						|| detectItem.getFault().equals("0")) {
					childHolderOne.rgFault.setItemChecked(0);
				} else {
					childHolderOne.rgFault.setItemChecked(1);
				}
			}
			if (detectItem.getWithout() == 1
					|| detectItem.getCannot_test() == 1) {
				childHolderOne.llDetail.setVisibility(View.GONE);
			} else {
				childHolderOne.llDetail.setVisibility(View.VISIBLE);
			}
			break;
		case TYPE_2:
			// 有测试时间
			final ChildHolderTwo childHolderTwo;
			if (convertView == null) {
				convertView = inflater.inflate(
						R.layout.item_detect_system_time, viewGroup, false);
				childHolderTwo = new ChildHolderTwo(convertView);
				convertView.setTag(childHolderTwo);
			} else {
				childHolderTwo = (ChildHolderTwo) convertView.getTag();
			}

			childHolderTwo.etRecordValue.setTag(detectItem);
			childHolderTwo.etMalfValue.setTag(detectItem);
			childHolderTwo.etStartDate.setTag(detectItem);
			childHolderTwo.etEndDate.setTag(detectItem);
			childHolderTwo.gvPic.setTag(R.id.tag_equip, detectItem);

			childHolderTwo.tvDetectTitle.setText(detectItemParent.getTitle());
			childHolderTwo.tvCode.setText(detectItem.getTagid());
			childHolderTwo.tvPosition.setText(detectItem.getPlace());
			childHolderTwo.tvDetectMethod.setText(detectItem.getReference());
			childHolderTwo.etRecordValue.setText(TextUtils.isEmpty(detectItem
					.getRecord()) ? detectItem.getDefault_record() : detectItem
					.getRecord());
			childHolderTwo.etMalfValue.setText(detectItem.getContent());
			childHolderTwo.etStartDate.setText(TextUtils.isEmpty(detectItem
					.getValue_1()) ? "" : DateUtils.timeStampToStr(Long
					.parseLong(detectItem.getValue_1())));
			childHolderTwo.etEndDate.setText(TextUtils.isEmpty(detectItem
					.getValue_2()) ? "" : DateUtils.timeStampToStr(Long
					.parseLong(detectItem.getValue_2())));

			childHolderTwo.etRecordValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderTwo.etRecordValue
									.getTag();
							bean.setRecord(s.toString());
						}
					});
			childHolderTwo.etMalfValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderTwo.etMalfValue
									.getTag();
							bean.setContent(s.toString());
						}
					});

			childHolderTwo.etStartDate
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderTwo.etStartDate
									.getTag();
							if (!TextUtils.isEmpty(s.toString())) {
								bean.setValue_1(DateUtils.fmtStrToDate(
										s.toString(), DateUtils.YMDHMS_FORMAT)
										.getTime()
										/ 1000 + "");
							} else {
								bean.setValue_1(s.toString());
							}
						}
					});

			childHolderTwo.etEndDate.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					Equipment bean = (Equipment) childHolderTwo.etEndDate
							.getTag();
					if (!TextUtils.isEmpty(s.toString())) {
						bean.setValue_2(DateUtils.fmtStrToDate(s.toString(),
								DateUtils.YMDHMS_FORMAT).getTime()
								/ 1000 + "");
					} else {
						bean.setValue_2(s.toString());
					}
				}
			});

			childHolderTwo.tvTime.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (v.getTag() == null) {
						Date startDate = new Date();
						childHolderTwo.etStartDate.setText(DateUtils
								.fmtDateToStr(startDate,
										DateUtils.YMDHMS_FORMAT));
						v.setTag(startDate.getTime());
						Drawable stopDraw = v.getContext().getResources()
								.getDrawable(R.mipmap.icon_detect_time_stop);
						stopDraw.setBounds(0, 0, stopDraw.getMinimumWidth(),
								stopDraw.getMinimumHeight());
						TextView time = (TextView) v;
						time.setCompoundDrawables(null, stopDraw, null, null);
					} else {
						Date endDate = new Date();
						childHolderTwo.etEndDate.setText(DateUtils
								.fmtDateToStr(endDate, DateUtils.YMDHMS_FORMAT));

						Log.e("time  ",
								(endDate.getTime() - ((Long) v.getTag()))
										/ 1000 + "");
						v.setTag(null);
						Drawable startDraw = v.getContext().getResources()
								.getDrawable(R.mipmap.icon_detect_time_start);
						startDraw.setBounds(0, 0, startDraw.getMinimumWidth(),
								startDraw.getMinimumHeight());
						TextView time = (TextView) v;
						time.setCompoundDrawables(null, startDraw, null, null);
					}
				}
			});

			refreshAdapter((MyAdapter) childHolderTwo.gvPic.getTag(),
					childHolderTwo.gvPic,
					(Equipment) childHolderTwo.gvPic.getTag(R.id.tag_equip));

			childHolderTwo.rgFault
					.setOnCheckChangedListener(new OnCheckedChangedListener() {

						@Override
						public void onItemChecked(MultiLineRadioGroup group,
								int position, boolean checked) {
							if (position == 0) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 1) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("1");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 2) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
								// childHolderZore.llPics.setVisibility(View.GONE);
							} else {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
							}

							EventBus.getDefault().post(
									new CheckUploadEvent(catePosition));
							notifyDataSetChanged();

						}
					});

			if (detectItem.getWithout() == 1) {
				// 无此项
				childHolderTwo.rgFault.setItemChecked(2);
			} else if (detectItem.getCannot_test() == 1) {
				// 无法测试
				childHolderTwo.rgFault.setItemChecked(3);
			} else {
				// 有此项
				if (TextUtils.isEmpty(detectItem.getFault())
						|| detectItem.getFault().equals("0")) {
					childHolderTwo.rgFault.setItemChecked(0);
				} else {
					childHolderTwo.rgFault.setItemChecked(1);
				}
			}
			if (detectItem.getWithout() == 1
					|| detectItem.getCannot_test() == 1) {
				childHolderTwo.llDetail.setVisibility(View.GONE);
			} else {
				childHolderTwo.llDetail.setVisibility(View.VISIBLE);
			}
			break;
		case TYPE_4:
			// 有当前值
			final ChildHolderFour childHolderFour;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_detect_system_cur,
						viewGroup, false);
				childHolderFour = new ChildHolderFour(convertView);
				convertView.setTag(childHolderFour);
			} else {
				childHolderFour = (ChildHolderFour) convertView.getTag();
			}

			childHolderFour.etRecordValue.setTag(detectItem);
			childHolderFour.etMalfValue.setTag(detectItem);
			childHolderFour.etCur.setTag(detectItem);
			childHolderFour.gvPic.setTag(R.id.tag_equip, detectItem);

			childHolderFour.tvDetectTitle.setText(detectItemParent.getTitle());
			childHolderFour.tvCode.setText(detectItem.getTagid());
			childHolderFour.tvPosition.setText(detectItem.getPlace());
			childHolderFour.tvDetectMethod.setText(detectItem.getReference());
			childHolderFour.etRecordValue.setText(TextUtils.isEmpty(detectItem
					.getRecord()) ? detectItem.getDefault_record() : detectItem
					.getRecord());
			childHolderFour.etMalfValue.setText(detectItem.getContent());
			childHolderFour.etRecordValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderFour.etRecordValue
									.getTag();
							bean.setRecord(s.toString());
						}
					});
			childHolderFour.etMalfValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderFour.etMalfValue
									.getTag();
							bean.setContent(s.toString());
						}
					});

			childHolderFour.etCur.addTextChangedListener(new TextWatcher() {
				/**
				 * 当输入框里面内容发生变化的时候回调的方法
				 */
				@Override
				public void onTextChanged(CharSequence s, int start, int count,
						int after) {

				}

				@Override
				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
				}

				@Override
				public void afterTextChanged(Editable s) {
					Equipment bean = (Equipment) childHolderFour.etCur.getTag();
					bean.setValue(s.toString());
				}
			});

			refreshAdapter((MyAdapter) childHolderFour.gvPic.getTag(),
					childHolderFour.gvPic,
					(Equipment) childHolderFour.gvPic.getTag(R.id.tag_equip));

			childHolderFour.rgFault
					.setOnCheckChangedListener(new OnCheckedChangedListener() {

						@Override
						public void onItemChecked(MultiLineRadioGroup group,
								int position, boolean checked) {
							if (position == 0) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 1) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("1");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 2) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
								// childHolderZore.llPics.setVisibility(View.GONE);
							} else {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
							}

							EventBus.getDefault().post(
									new CheckUploadEvent(catePosition));
							notifyDataSetChanged();

						}
					});

			if (detectItem.getWithout() == 1) {
				// 无此项
				childHolderFour.rgFault.setItemChecked(2);
			} else if (detectItem.getCannot_test() == 1) {
				// 无法测试
				childHolderFour.rgFault.setItemChecked(3);
			} else {
				// 有此项
				if (TextUtils.isEmpty(detectItem.getFault())
						|| detectItem.getFault().equals("0")) {
					childHolderFour.rgFault.setItemChecked(0);
				} else {
					childHolderFour.rgFault.setItemChecked(1);
				}
			}
			if (detectItem.getWithout() == 1
					|| detectItem.getCannot_test() == 1) {
				childHolderFour.llDetail.setVisibility(View.GONE);
			} else {
				childHolderFour.llDetail.setVisibility(View.VISIBLE);
			}
			break;
		case TYPE_5:
			// 正常点数、异常点数
			final ChildHolderFive childHolderFive;
			if (convertView == null) {
				convertView = inflater.inflate(
						R.layout.item_detect_system_point, viewGroup, false);
				childHolderFive = new ChildHolderFive(convertView);
				convertView.setTag(childHolderFive);
			} else {
				childHolderFive = (ChildHolderFive) convertView.getTag();
			}

			childHolderFive.etRecordValue.setTag(detectItem);
			childHolderFive.etMalfValue.setTag(detectItem);
			childHolderFive.etNormalValue.setTag(detectItem);
			childHolderFive.etErrorValue.setTag(detectItem);
			childHolderFive.gvPic.setTag(R.id.tag_equip, detectItem);

			childHolderFive.tvDetectTitle.setText(detectItemParent.getTitle());
			childHolderFive.tvCode.setText(detectItem.getTagid());
			childHolderFive.tvPosition.setText(detectItem.getPlace());
			childHolderFive.tvDetectMethod.setText(detectItem.getReference());
			childHolderFive.etNormalValue.setText(detectItem.getValue_1());
			childHolderFive.etErrorValue.setText(detectItem.getValue_2());
			childHolderFive.etRecordValue.setText(TextUtils.isEmpty(detectItem
					.getRecord()) ? detectItem.getDefault_record() : detectItem
					.getRecord());
			childHolderFive.etMalfValue.setText(detectItem.getContent());
			childHolderFive.etRecordValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderFive.etRecordValue
									.getTag();
							bean.setRecord(s.toString());
						}
					});
			childHolderFive.etMalfValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderFive.etMalfValue
									.getTag();
							bean.setContent(s.toString());
						}
					});

			childHolderFive.etNormalValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderFive.etNormalValue
									.getTag();
							bean.setValue_1(s.toString());
						}
					});

			childHolderFive.etErrorValue
					.addTextChangedListener(new TextWatcher() {
						/**
						 * 当输入框里面内容发生变化的时候回调的方法
						 */
						@Override
						public void onTextChanged(CharSequence s, int start,
								int count, int after) {

						}

						@Override
						public void beforeTextChanged(CharSequence s,
								int start, int count, int after) {
						}

						@Override
						public void afterTextChanged(Editable s) {
							Equipment bean = (Equipment) childHolderFive.etErrorValue
									.getTag();
							bean.setValue_2(s.toString());
						}
					});

			refreshAdapter((MyAdapter) childHolderFive.gvPic.getTag(),
					childHolderFive.gvPic,
					(Equipment) childHolderFive.gvPic.getTag(R.id.tag_equip));

			childHolderFive.rgFault
					.setOnCheckChangedListener(new OnCheckedChangedListener() {

						@Override
						public void onItemChecked(MultiLineRadioGroup group,
								int position, boolean checked) {
							if (position == 0) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 1) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("1");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								// childHolderZore.llPics.setVisibility(View.VISIBLE);
							} else if (position == 2) {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
								// childHolderZore.llPics.setVisibility(View.GONE);
							} else {
								mList.get(groupPosition).getChildList()
										.get(childPosition).setFault("0");
								mList.get(groupPosition).getChildList()
										.get(childPosition).setWithout(0);
								mList.get(groupPosition).getChildList()
										.get(childPosition).setCannot_test(1);
								mList.get(groupPosition).getChildList()
										.get(childPosition).getImageList()
										.clear();
							}

							EventBus.getDefault().post(
									new CheckUploadEvent(catePosition));
							notifyDataSetChanged();

						}
					});

			if (detectItem.getWithout() == 1) {
				// 无此项
				childHolderFive.rgFault.setItemChecked(2);
			} else if (detectItem.getCannot_test() == 1) {
				// 无法测试
				childHolderFive.rgFault.setItemChecked(3);
			} else {
				// 有此项
				if (TextUtils.isEmpty(detectItem.getFault())
						|| detectItem.getFault().equals("0")) {
					childHolderFive.rgFault.setItemChecked(0);
				} else {
					childHolderFive.rgFault.setItemChecked(1);
				}
			}
			if (detectItem.getWithout() == 1
					|| detectItem.getCannot_test() == 1) {
				childHolderFive.llDetail.setVisibility(View.GONE);
			} else {
				childHolderFive.llDetail.setVisibility(View.VISIBLE);
			}
			break;
		}

		return convertView;

	}

	@Override
	public boolean isChildSelectable(int i, int i1) {
		return true;
	}

	class GroupHolder {
		TextView mGroupTitleTv;
		TextView tvMore;

		public GroupHolder(View view) {
			mGroupTitleTv = (TextView) view.findViewById(R.id.groupTitle);
			tvMore = (TextView) view.findViewById(R.id.tvMore);
		}
	}

	class ChildHolderZore {
		TextView tvCode;
		TextView tvPosition;
		TextView tvDetectMethod;
		TextView tvStatus;
		EditText etRecordValue;
		EditText etMalfValue;
		GridView gvPic;
		MultiLineRadioGroup rgFault;
		LinearLayout llDetail;
		TextView tvDetectTitle;

		public ChildHolderZore(View convertView) {
			tvCode = (TextView) convertView.findViewById(R.id.tvCode);
			tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
			tvDetectMethod = (TextView) convertView
					.findViewById(R.id.tvDetectMethod);
			// tvStatus = (TextView) convertView.findViewById(R.id.tvStatus);
			etRecordValue = (EditText) convertView
					.findViewById(R.id.etRecordValue);
			etMalfValue = (EditText) convertView.findViewById(R.id.etMalfValue);
			gvPic = (GridView) convertView.findViewById(R.id.gvPic);
			rgFault = (MultiLineRadioGroup) convertView
					.findViewById(R.id.rgFault);
			llDetail = (LinearLayout) convertView.findViewById(R.id.llDetail);
			tvDetectTitle = (TextView) convertView
					.findViewById(R.id.tvDetectTitle);
		}
	}

	class ChildHolderOne {
		TextView tvCode;
		TextView tvPosition;
		TextView tvDetectMethod;
		EditText etPre;
		EditText etCur;
		EditText etRecordValue;
		EditText etMalfValue;
		GridView gvPic;
		LinearLayout llDetail;
		MultiLineRadioGroup rgFault;
		TextView tvDetectTitle;

		public ChildHolderOne(View convertView) {
			tvCode = (TextView) convertView.findViewById(R.id.tvCode);
			tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
			tvDetectMethod = (TextView) convertView
					.findViewById(R.id.tvDetectMethod);
			etPre = (EditText) convertView.findViewById(R.id.etPre);
			etCur = (EditText) convertView.findViewById(R.id.etCur);
			etRecordValue = (EditText) convertView
					.findViewById(R.id.etRecordValue);
			etMalfValue = (EditText) convertView.findViewById(R.id.etMalfValue);
			gvPic = (GridView) convertView.findViewById(R.id.gvPic);
			llDetail = (LinearLayout) convertView.findViewById(R.id.llDetail);
			rgFault = (MultiLineRadioGroup) convertView
					.findViewById(R.id.rgFault);
			tvDetectTitle = (TextView) convertView
					.findViewById(R.id.tvDetectTitle);
		}
	}

	class ChildHolderTwo {
		TextView tvCode;
		TextView tvPosition;
		TextView tvDetectMethod;
		EditText etStartDate;
		EditText etEndDate;
		EditText etRecordValue;
		EditText etMalfValue;
		TextView tvTime;
		GridView gvPic;
		LinearLayout llDetail;
		MultiLineRadioGroup rgFault;
		TextView tvDetectTitle;

		public ChildHolderTwo(View convertView) {
			tvCode = (TextView) convertView.findViewById(R.id.tvCode);
			tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
			tvDetectMethod = (TextView) convertView
					.findViewById(R.id.tvDetectMethod);
			etStartDate = (EditText) convertView.findViewById(R.id.etStartDate);
			etEndDate = (EditText) convertView.findViewById(R.id.etEndDate);
			etRecordValue = (EditText) convertView
					.findViewById(R.id.etRecordValue);
			etMalfValue = (EditText) convertView.findViewById(R.id.etMalfValue);
			gvPic = (GridView) convertView.findViewById(R.id.gvPic);
			tvTime = (TextView) convertView.findViewById(R.id.tvTime);
			llDetail = (LinearLayout) convertView.findViewById(R.id.llDetail);
			rgFault = (MultiLineRadioGroup) convertView
					.findViewById(R.id.rgFault);
			tvDetectTitle = (TextView) convertView
					.findViewById(R.id.tvDetectTitle);
		}
	}

	class ChildHolderFour {
		TextView tvCode;
		TextView tvPosition;
		TextView tvDetectMethod;
		EditText etCur;
		EditText etRecordValue;
		EditText etMalfValue;
		GridView gvPic;
		LinearLayout llDetail;
		MultiLineRadioGroup rgFault;
		TextView tvDetectTitle;

		public ChildHolderFour(View convertView) {
			tvCode = (TextView) convertView.findViewById(R.id.tvCode);
			tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
			tvDetectMethod = (TextView) convertView
					.findViewById(R.id.tvDetectMethod);
			etCur = (EditText) convertView.findViewById(R.id.etCur);
			etRecordValue = (EditText) convertView
					.findViewById(R.id.etRecordValue);
			etMalfValue = (EditText) convertView.findViewById(R.id.etMalfValue);
			gvPic = (GridView) convertView.findViewById(R.id.gvPic);
			llDetail = (LinearLayout) convertView.findViewById(R.id.llDetail);
			rgFault = (MultiLineRadioGroup) convertView
					.findViewById(R.id.rgFault);
			tvDetectTitle = (TextView) convertView
					.findViewById(R.id.tvDetectTitle);
		}
	}

	class ChildHolderFive {
		TextView tvCode;
		TextView tvPosition;
		TextView tvDetectMethod;
		EditText etNormalValue;
		EditText etErrorValue;
		EditText etRecordValue;
		EditText etMalfValue;
		GridView gvPic;
		LinearLayout llDetail;
		MultiLineRadioGroup rgFault;
		TextView tvDetectTitle;

		public ChildHolderFive(View convertView) {
			tvCode = (TextView) convertView.findViewById(R.id.tvCode);
			tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
			tvDetectMethod = (TextView) convertView
					.findViewById(R.id.tvDetectMethod);
			etNormalValue = (EditText) convertView
					.findViewById(R.id.etNormalValue);
			etErrorValue = (EditText) convertView
					.findViewById(R.id.etErrorValue);
			etRecordValue = (EditText) convertView
					.findViewById(R.id.etRecordValue);
			etMalfValue = (EditText) convertView.findViewById(R.id.etMalfValue);
			gvPic = (GridView) convertView.findViewById(R.id.gvPic);
			llDetail = (LinearLayout) convertView.findViewById(R.id.llDetail);
			rgFault = (MultiLineRadioGroup) convertView
					.findViewById(R.id.rgFault);
			tvDetectTitle = (TextView) convertView
					.findViewById(R.id.tvDetectTitle);
		}
	}

	class MyAdapter extends BaseAdapter {
		Equipment detectItem;

		public MyAdapter(Equipment detectItem) {
			this.detectItem = detectItem;
		}

		@Override
		public int getCount() {
			if (detectItem.getImageList().size() > 0) {
				return detectItem.getImageList().size() + 2;
			}
			return 1;
		}

		@Override
		public Object getItem(int position) {
			return detectItem;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View inflate = inflater.inflate(R.layout.simple_imageview, null);
			ImageView iv_simple = (ImageView) inflate
					.findViewById(R.id.iv_simple);
			ImageView iv_delpic = (ImageView) inflate
					.findViewById(R.id.iv_delpic);

			if (detectItem.getImageList().size() <= 0) {
				iv_simple.setImageDrawable(mContext.getResources().getDrawable(
						R.mipmap.add_square));
			} else {
				if (position == detectItem.getImageList().size()) {
					iv_simple.setImageDrawable(mContext.getResources()
							.getDrawable(R.mipmap.add_square));
				} else if (position == detectItem.getImageList().size() + 1) {
					iv_simple.setImageDrawable(mContext.getResources()
							.getDrawable(R.mipmap.delpic));
				} else {
					if (detectItem.isDelType()) {
						iv_delpic.setVisibility(View.VISIBLE);
					} else {
						iv_delpic.setVisibility(View.GONE);
					}
					String sourcePath = detectItem.getImageList().get(position);
					GlideUtil.load(mContext, sourcePath, iv_simple);
				}
			}
			return inflate;
		}

		public Equipment getDetectItem() {
			return detectItem;
		}

		public void setDetectItem(Equipment detectItem) {
			this.detectItem = detectItem;
		}

	}

	private void refreshAdapter(MyAdapter adapter, final GridView gvPic,
			final Equipment detectItem) {

		if (detectItem.getImageList().size() <= 0) {
			detectItem.setDelType(false);
		}

		if (adapter == null) {
			final MyAdapter newAdapter = new MyAdapter(detectItem);
			float density = DeviceUtil.getInstance().getBiLi(); // 像素密度
			int screenWidth = DeviceUtil.getInstance().getScreenWidth();
			// 15是父节点的padding 2是左右两边
			screenWidth -= 15 * 2 * density;
			// 求出最大可放的图片个数 60是item的宽度 10是item之间的间距
			int maxNum = (int) Math.floor(screenWidth / ((60 + 10) * density));
			Log.e("maxNum ", maxNum + "");

			gvPic.setNumColumns(maxNum);
			gvPic.setAdapter(newAdapter);
			gvPic.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long arg3) {
					Equipment childItem = (Equipment) parent.getAdapter()
							.getItem(position);
					if (childItem.isDelType()) {
						if (childItem.getImageList().size() > 0) {

							if (position == childItem.getImageList().size()) {
								addPic(view, childItem,
										childItem.getParentPosition(),
										childItem.getChildPosition());
							} else if (position == childItem.getImageList()
									.size() + 1) {
								childItem.setDelType(false);
								refreshAdapter(newAdapter, gvPic, childItem);
							} else {
								childItem.getImageList().remove(position);
								refreshAdapter(newAdapter, gvPic, childItem);
								EventBus.getDefault().post(
										new CheckUploadEvent(catePosition));
							}
						}
					} else {
						if (childItem.getImageList().size() <= 0) {
							addPic(view, childItem,
									childItem.getParentPosition(),
									childItem.getChildPosition());
						} else {
							if (childItem.getImageList().size() == position) {
								addPic(view, childItem,
										childItem.getParentPosition(),
										childItem.getChildPosition());
							} else if (childItem.getImageList().size() + 1 == position) {
								childItem.setDelType(true);
								refreshAdapter(newAdapter, gvPic, childItem);
							} else {
								String[] urls = new String[childItem
										.getImageList().size()];
								for (int i = 0, n = childItem.getImageList()
										.size(); i < n; i++) {
									urls[i] = childItem.getImageList().get(i);
								}

								Intent intent = new Intent(gvPic.getContext(),
										ImagePagerActivity.class);
								intent.putExtra(
										ImagePagerActivity.EXTRA_IMAGE_URLS,
										urls);
								intent.putExtra(
										ImagePagerActivity.EXTRA_IMAGE_INDEX,
										position);
								gvPic.getContext().startActivity(intent);
							}
						}
					}
				}
			});
			gvPic.setTag(newAdapter);
		} else {
			adapter.setDetectItem(detectItem);
			adapter.notifyDataSetChanged();
		}

	}

	private void addPic(View view, final Equipment detectItem,
			final int parentId, final int childId) {
		if (detectItem.getImageList().size() >= max) {
			ToastUtil.getInstances().showMsg("最多只能添加" + max + "张图片");
			return;
		}
		PicSelectConstans.pic_tag = 2;
		detectItem.setDelType(false);
		if (imm.isActive()) {
			imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
		}
		AppConfig.detectParentPosition = parentId;
		AppConfig.detectChildPosition = childId;
		mPickPopView.showPopWindow();
	}

	@Override
	public int getChildType(int groupPosition, int childPosition) {
		String kind = mList.get(groupPosition).getChildList()
				.get(childPosition).getKind();
		if (Integer.parseInt(kind) == 0) {
			// 有当前状态的选项
			return TYPE_0;
		} else if (Integer.parseInt(kind) == 1) {
			// 上次值、当前值
			return TYPE_1;
		} else if (Integer.parseInt(kind) == 2) {
			// 测试时间的
			return TYPE_2;
		} else if (Integer.parseInt(kind) == 3) {
			return TYPE_3;
		} else if (Integer.parseInt(kind) == 4) {
			return TYPE_4;
		} else if (Integer.parseInt(kind) == 5) {
			// 正常点数、异常点数
			return TYPE_5;
		}

		try {
			throw new Exception("kind没有没有等于" + Integer.parseInt(kind) + "的类别");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return TYPE_0;
	}

	@Override
	public int getChildTypeCount() {
		return 10;
	}

	public ArrayList<DetectItemParent> getmList() {
		return mList;
	}

}